package ca.jsbr.canvaswar 
{
	import ca.jsbr.as2js_lib.display.canvas.Node2D;
	import ca.jsbr.canvaswar.screen.Screen;
	import ca.jsbr.canvaswar.screen.Screens;
	/**
	 * ...
	 * @author jsbr [me@jsbr.ca]
	 */
	public class ScreenManager 
	{
		static private var _instance:ScreenManager;
		private var _root:Node2D;
		private var _screen:Screen;
		private var _screens:Object;
		
		public function ScreenManager() 
		{
			//_screens = new Screens();
			_root = new Node2D();
			_root.name="ScreenManagerRoot"
		}
		
		public function setScreensObject(screens:Object):void
		{
			_screens = screens;
		}
		
		public function openScreen(name:String):Screen
		{
			if (_screen)
				_root.removeChild(_screen);
			_screen = _screens["screen_"+name]();
			_root.addChild(_screen);
			_screen.init();
		}
		
		public function openPopup():Screen
		{
			
		}
		
		public function get root():Node2D 
		{
			return _root;
		}
		
		
		public function destroy():void
		{
			_instance=null;
		}
				
		public static function getInstance():ScreenManager
		{
			if(!_instance)
				_instance=new ScreenManager()
			return _instance;
		}
		
		
		
	}

}